<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="k8s," />





  <link rel="alternate" href="/atom.xml" title="yszhao的博客" type="application/atom+xml" />






<meta name="description" content="一、redhat&#x2F;openEluer 22&#x2F;Centos 系统 安装k8s1.1 更新源wget -O &#x2F;etc&#x2F;yum.repos.d&#x2F;CentOS-Base.repo http:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;repo&#x2F;Centos-7.repo编辑替换  %s&#x2F;$releasever&#x2F;7&#x2F;g 设置仓库，需要安装所需的软件包。yum-utils 提供了 yum-config-mana">
<meta property="og:type" content="article">
<meta property="og:title" content="k8s安装配置">
<meta property="og:url" content="http://example.com/posts/5951e8f7.html">
<meta property="og:site_name" content="yszhao的博客">
<meta property="og:description" content="一、redhat&#x2F;openEluer 22&#x2F;Centos 系统 安装k8s1.1 更新源wget -O &#x2F;etc&#x2F;yum.repos.d&#x2F;CentOS-Base.repo http:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;repo&#x2F;Centos-7.repo编辑替换  %s&#x2F;$releasever&#x2F;7&#x2F;g 设置仓库，需要安装所需的软件包。yum-utils 提供了 yum-config-mana">
<meta property="og:locale">
<meta property="article:published_time" content="2024-05-16T11:58:36.000Z">
<meta property="article:modified_time" content="2024-12-04T07:16:45.373Z">
<meta property="article:author" content="yszhao">
<meta property="article:tag" content="k8s">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://example.com/posts/5951e8f7.html"/>





  <title>k8s安装配置 | yszhao的博客</title>
  








<meta name="generator" content="Hexo 5.4.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">yszhao的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">记录我的生活 学习</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://example.com/posts/5951e8f7.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yszhao的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">k8s安装配置</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2024-05-16T19:58:36+08:00">
                2024-05-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="一、redhat-openEluer-22-Centos-系统-安装k8s"><a href="#一、redhat-openEluer-22-Centos-系统-安装k8s" class="headerlink" title="一、redhat/openEluer 22/Centos 系统 安装k8s"></a>一、redhat/openEluer 22/Centos 系统 安装k8s</h1><h2 id="1-1-更新源"><a href="#1-1-更新源" class="headerlink" title="1.1 更新源"></a>1.1 更新源</h2><p>wget -O /etc/yum.repos.d/CentOS-Base.repo <a target="_blank" rel="noopener" href="http://mirrors.aliyun.com/repo/Centos-7.repo">http://mirrors.aliyun.com/repo/Centos-7.repo</a><br>编辑替换  %s/$releasever/7/g</p>
<p>设置仓库，需要安装所需的软件包。yum-utils 提供了 yum-config-manager ，<br>并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2</p>
<p>yum install -y yum-utils device-mapper-persistent-data lvm2</p>
<p>yum-config-manager –add-repo <a target="_blank" rel="noopener" href="https://download.docker.com/linux/centos/docker-ce.repo">https://download.docker.com/linux/centos/docker-ce.repo</a><br>编辑替换  %s/$releasever/7/g</p>
<h2 id="1-2-安装-docker"><a href="#1-2-安装-docker" class="headerlink" title="1.2 安装 docker"></a>1.2 安装 docker</h2><p>yum install docker-ce</p>
<h2 id="1-3-新增k8s源及安装"><a href="#1-3-新增k8s源及安装" class="headerlink" title="1.3 新增k8s源及安装"></a>1.3 新增k8s源及安装</h2><p>新增k8s源<br>cat &lt;<EOF > /etc/yum.repos.d/kubernetes.repo<br>[kubernetes]<br>name=Kubernetes<br>baseurl=<a target="_blank" rel="noopener" href="https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/">https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/</a><br>enabled=1<br>gpgcheck=0<br>EOF</p>
<p>yum install kubeadm kubelet kubectl </p>
<h1 id="二、ubuntu-系统安装-k8s"><a href="#二、ubuntu-系统安装-k8s" class="headerlink" title="二、ubuntu 系统安装 k8s"></a>二、ubuntu 系统安装 k8s</h1><p> sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common</p>
<p> curl -s <a target="_blank" rel="noopener" href="https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg">https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg</a> | sudo apt-key add -</p>
<p> sudo apt-add-repository “deb <a target="_blank" rel="noopener" href="https://mirrors.aliyun.com/kubernetes/apt/">https://mirrors.aliyun.com/kubernetes/apt/</a> kubernetes-xenial main”</p>
<p> sudo apt-get update</p>
<p>  vi /etc/apt/sources.list</p>
<p> deb <a target="_blank" rel="noopener" href="https://mirrors.aliyun.com/kubernetes/apt">https://mirrors.aliyun.com/kubernetes/apt</a> kubernetes-xenial main</p>
<p> apt-get update<br> sudo apt update</p>
<p> #sudo apt install -y kubelet=1.26.1-00 kubeadm=1.26.1-00 kubectl=1.26.1-00</p>
<p> sudo apt install kubelet kubeadm kubectl<br> sudo apt-mark hold kubelet kubeadm kubectl</p>
<h1 id="三、必要的系统设置"><a href="#三、必要的系统设置" class="headerlink" title="三、必要的系统设置"></a>三、必要的系统设置</h1><h2 id="3-1-关闭-selinux-关闭防火墙【暂时】（redhat系统）"><a href="#3-1-关闭-selinux-关闭防火墙【暂时】（redhat系统）" class="headerlink" title="3.1 关闭 selinux  关闭防火墙【暂时】（redhat系统）"></a>3.1 关闭 selinux  关闭防火墙【暂时】（redhat系统）</h2><p>零时关闭<br>   setenforce 0  </p>
<p>永久关闭<br>       vi /etc/selinux/config<br>       将参数修改为SELINUX=disabled</p>
<p>关闭防火墙</p>
<p>   systemctl stop iptables</p>
<p>   systemctl stop firewalld</p>
<p>   systemct stop ufw</p>
<h2 id="3-2-禁用交换分区"><a href="#3-2-禁用交换分区" class="headerlink" title="3.2 禁用交换分区"></a>3.2 禁用交换分区</h2><p>   swapoff -a </p>
<p>   /etc/fstab 文件下永久关闭<br>   打开/etc/fstab注释掉swap那一行</p>
<p>   sed -i ‘s/.<em>swap.</em>/#&amp;/‘ /etc/fstab  </p>
<h2 id="3-3-开启端口转发"><a href="#3-3-开启端口转发" class="headerlink" title="3.3 开启端口转发"></a>3.3 开启端口转发</h2><p>   vim  /proc/sys/net/ipv4/ip_forward<br>   sysctl -w net.ipv4.ip_forward=1</p>
<h2 id="3-4-修改内核参数"><a href="#3-4-修改内核参数" class="headerlink" title="3.4 修改内核参数"></a>3.4 修改内核参数</h2><p>cat &lt;<EOF >  /etc/sysctl.d/k8s.conf<br>net.bridge.bridge-nf-call-ip6tables = 1<br>net.bridge.bridge-nf-call-iptables = 1<br>EOF<br>sysctl –system </p>
<h2 id="3-5-设置时区更新时间"><a href="#3-5-设置时区更新时间" class="headerlink" title="3.5 设置时区更新时间"></a>3.5 设置时区更新时间</h2><pre><code> timedatectl  查看时区
 
 设置时区
 timedatectl set-timezone Asia/Shanghai
 
</code></pre>
<h2 id="配置host"><a href="#配置host" class="headerlink" title="配置host"></a>配置host</h2><pre><code>vim /etc/hosts

 
</code></pre>
<h1 id="三、master-节点配置"><a href="#三、master-节点配置" class="headerlink" title="三、master 节点配置"></a>三、master 节点配置</h1><h2 id="3-1-配置项-解释"><a href="#3-1-配置项-解释" class="headerlink" title="3.1 配置项 解释"></a>3.1 配置项 解释</h2><p> 自定义镜像进行初始化(推荐)<br> 使用自定义kubernets镜像仓库进行初始化</p>
<p> apiserver-advertise-address: 配置 apiserver ip  本机ip<br>                             指明用 Master 的哪个 interface 与 Cluster 的其他节点通信。<br>                             如果 Master 有多个 interface，建议明确指定，如果不指定，kubeadm 会自动选择有默认网关的 interface。<br>                             这里的ip为master节点ip，记得更换</p>
<p> apiserver-bind-port       : 配置 apiserver 端口 默认 6443</p>
<p> control-plane-endpoint    : 配置 控制端   ip  默认本机ip<br>                             cluster-endpoint 是映射到该 IP 的自定义 DNS 名称，这里配置hosts映射：192.168.0.113   cluster-endpoint。<br>                             这将允许你将 –control-plane-endpoint=cluster-endpoint 传递给 kubeadm init，并将相同的 DNS 名称传递给 kubeadm join。<br>                             稍后你可以修改 cluster-endpoint 以指向高可用性方案中的负载均衡器的地址。</p>
<p> service-cidr               这个参数指定了 Kubernetes 集群中服务（Service）的 IP 地址范围。在该示例中，服务 IP 地址将从 10.119.0.0 开始分配。</p>
<p> service-dns-domain         这个参数指定了 Kubernetes 集群中服务的 DNS 域名。在该示例中，服务的 DNS 域名将使用 “cluster.local”。</p>
<p> pod-network-cidr  :    这个参数指定了 Kubernetes 集群中 Pod 的 IP 地址范围。在该示例中，Pod 的 IP 地址将从 10.120.0.0 开始分配。<br>                        指定 Pod 网络的范围。Kubernetes 支持多种网络方案，而且不同网络方案对<br>                        –pod-network-cidr有自己的要求，这里设置为10.244.0.0/16 是因为我们将使用 flannel 网络方案<br>                        必须设置成这个 CIDR。</p>
<p> image-repository           这个用于指定从什么位置来拉取镜像（1.13版本才有的），默认值是k8s.gcr.io，<br>                            我们将其指定为国内镜像地址：registry.aliyuncs.com/google_containers</p>
<p> kubernetes-version        指定kubenets版本号，默认值是stable-1，会导致从<a target="_blank" rel="noopener" href="https://dl.k8s.io/release/stable-1.txt%E4%B8%8B%E8%BD%BD%E6%9C%80%E6%96%B0%E7%9A%84%E7%89%88%E6%9C%AC%E5%8F%B7%EF%BC%8C">https://dl.k8s.io/release/stable-1.txt下载最新的版本号，</a><br>                           我们可以将其指定为固定版本（v1.22.1）来跳过网络请求</p>
<h2 id="3-2配置示例："><a href="#3-2配置示例：" class="headerlink" title="3.2配置示例："></a>3.2配置示例：</h2><p> kubeadm init <br> –apiserver-advertise-address 192.168.240.11 <br> –apiserver-bind-port 6443 <br> –control-plane-endpoint 192.168.240.11 <br> –service-cidr=10.119.0.0/16 <br> –service-dns-domain=”cluster.local” <br> –pod-network-cidr=10.120.0.0/16 <br> –image-repository registry.aliyuncs.com/google_containers </p>
<p> kubeadm init <br>  –apiserver-advertise-address=192.168.100.203 <br>  –image-repository registry.aliyuncs.com/google_containers <br>  –service-cidr=10.119.0.0/16 <br>  –pod-network-cidr=10.120.0.0/16 <br>  –kubernetes-version v1.28.2</p>
<p> kubeadm init <br>   –apiserver-advertise-address=192.168.31.200 <br>   –image-repository registry.aliyuncs.com/google_containers <br>   –kubernetes-version v1.18.0 <br>   –service-cidr=10.96.0.0/12 <br>   –pod-network-cidr=10.244.0.0/16</p>
<h2 id="3-3-配置-kubectl"><a href="#3-3-配置-kubectl" class="headerlink" title="3.3 配置 kubectl"></a>3.3 配置 kubectl</h2><p>   mkdir -p $HOME/.kube<br>   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config<br>   sudo chown $(id -u):$(id -g) $HOME/.kube/config<br>   echo ‘export KUBECONFIG=$HOME/.kube/config’ &gt;&gt; $HOME/.bashrc<br>   source ~/.bashrc</p>
<h2 id="3-3-配置网络"><a href="#3-3-配置网络" class="headerlink" title="3.3 配置网络"></a>3.3 配置网络</h2><p>   kubectl apply -f <a target="_blank" rel="noopener" href="https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml">https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml</a></p>
<p>   如果被墙，可以直接保存下列文件进行安装</p>
<p>   kubectl apply -f kube-flannel.yaml</p>
<h1 id="四、node-节点配置"><a href="#四、node-节点配置" class="headerlink" title="四、node 节点配置"></a>四、node 节点配置</h1><h2 id="4-1-配置文件处理"><a href="#4-1-配置文件处理" class="headerlink" title="4.1 配置文件处理"></a>4.1 配置文件处理</h2><p> mkdir -p $HOME/.kube</p>
<p> 复制master节点的 /etc/kubernetes/admin.conf 到 node节点 $HOME/.kube/config</p>
<p> sudo  $(id -u):$(id -g) $HOME/.kube/config</p>
<p> echo ‘export KUBECONFIG=$HOME/.kube/config’ &gt;&gt; $HOME/.bashrc</p>
<p> source ~/.bashrc</p>
<h2 id="4-2-加入节点"><a href="#4-2-加入节点" class="headerlink" title="4.2 加入节点"></a>4.2 加入节点</h2><p>   可以master 节点执行  kubeadm token create –print-join-command 获取加入节点命令</p>
<p>   kubeadm join 172.17.131.4:6443 –token decqn7.lwcygbjmzof0xny3  <br>   –discovery-token-ca-cert-hash sha256:8f0e8d2c04e38c7aa291d8b47be2bd8a5127bf1071263e01bdd5602ab331a01d</p>
<h1 id="五、相关命令"><a href="#五、相关命令" class="headerlink" title="五、相关命令"></a>五、相关命令</h1><p> 如何生成 Kubeadm Join 命令？<br> 您可以使用 command 生成 join 命令。kubeadm token create –print-join-command</p>
<p> 重置节点（清除kubeadm信息）<br> kubeadm reset</p>
<p> 查看 pod 节点<br> kubectl get nodes</p>
<p> 删除的节点<br> kubectl delete node <node_name></p>
<p>于官网镜像在国内访问不稳定，会出现访问失败。<br>使用国内镜像进行替换下载，在此pause使用3.9会导致集群无法初始化，还需要下载pause:3.6<br>以下命令在每台服务器上执行<br>使用自定义镜像仓库拉取镜像<br>kubeadm config images pull  <br>–image-repository registry.aliyuncs.com/google_containers <br>–kubernetes-version v1.28.2</p>
<h1 id="六-报错"><a href="#六-报错" class="headerlink" title="六 报错"></a>六 报错</h1><p> 报错如下<br> “open /run/systemd/resolve/resolv.conf: no such file or directory” pod=”kubelet<br> 解决：<br> yum install systemd-resolved 解决</p>
<p>报错如下：<br>combined from similar events): Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox &amp;quot;4d992cde6a671b8fa3264a90f5f11aa01d1713376abf0cdf9a4e27ec82860185&amp;quot;: plugin type=&amp;quot;flannel&amp;quot; failed (add): loadFlannelSubnetEnv<br>failed: open /run/flannel/subnet.env: no such file or directory</p>
<p>解决：<br>配置 /run/flannel/subnet.env<br>pod 网络信息 </p>
<p>FLANNEL_NETWORK=10.120.0.0/16<br>FLANNEL_SUBNET=10.120.0.1/24<br>FLANNEL_MTU=1450<br>FLANNEL_IPMASQ=true</p>
<p>报错如下：<br>[preflight] Running pre-flight checks<br>error execution phase preflight: [preflight] Some fatal errors occurred:<br>    [ERROR FileContent–proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1<br>[preflight] If you know what you are doing, you can make a check non-fatal with <code>--ignore-preflight-errors=...</code><br>To see the stack trace of this error execute with –v=5 or higher</p>
<p> 解决：<br>sysctl -w net.ipv4.ip_forward=1</p>
<p>报错如下：</p>
<p> NotReady message:Network plugin returns error: cni plugin not initialized<br> to get sandbox image &quot;registry.k8s.i</p>
<p> evel=info msg=”Stop CRI service”<br> 024-05-31T02:22:27.294384683Z” level=info msg=”stop pulling image registry.k8s.io/pause:3.8: active requests=1, bytes&gt;<br> 024-05-31T02:22:27.294515739Z” level=info msg=”trying next host” error=”failed to do request: Head &quot;<a target="_blank" rel="noopener" href="https://us-west2&gt;/">https://us-west2&gt;</a> </p>
<p>解决</p>
<p>containerd config default &gt; /etc/containerd/config.toml</p>
<p>修改<br>sandbox_image = “registry.aliyuncs.com/google_containers/pause:3.9”</p>
<p>systemctl restart containerd</p>
<p>mkdir /etc/containerd<br>containerd config default &gt; /etc/containerd/config.toml<br>sed -i ‘/sandbox_image/s#registry.k8s.io/pause:3.8#registry.aliyuncs.com/google_containers/pause:3.9#g’ /etc/containerd/config.toml<br>sed -i ‘/SystemdCgroup/s/false/true/‘ /etc/containerd/config.toml<br>systemctl restart containerd</p>
<p>发现不了节点报错<br><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_32264301/article/details/125486521">https://blog.csdn.net/qq_32264301/article/details/125486521</a></p>
<p> error=”rpc error: code = Unavailable desc = error reading from server: EOF” module=libcontainerd namespace=moby</p>
<p>报错<br>Error registering network: failed to acquire lease: subnet “10.244.0.0/16”<br>specified in the flannel net config doesn’t contain “10.120.0.0/24” PodCIDR of the “ubuntuutoootest” node </p>
<p>修改 kube-flannel.yml</p>
<p>net-conf.json: |<br>    {<br>      “Network”: “10.120.0.0/16”,<br>      “EnableNFTables”: false,<br>      “Backend”: {<br>        “Type”: “vxlan”<br>      }<br>    }</p>
<hr>
<h1 id="k8组件"><a href="#k8组件" class="headerlink" title="k8组件"></a>k8组件</h1><p>k8s的主要组件，以及它们主要是用来干什么的：</p>
<p>3.1 「主节点（Master）」<br>主节点负责管理集群的整体状态和控制工作节点的操作。它包括以下组件：</p>
<p>「API Server：」 提供了K8s API的入口，用于与Kubernetes进行交互。<br>「Controller Manager：」 负责监控系统状态，确保实际状态符合期望状态。<br>「Scheduler：」 负责将Pod调度到工作节点上运行。</p>
<p>3.2 「工作节点（Node）」<br>工作节点是集群中的计算资源，用于运行容器。每个工作节点包括以下组件：</p>
<p>「Kubelet：」 负责与主节点通信，确保在节点上运行所需的Pod。<br>「Container Runtime：」 用于启动和管理容器的软件，如Docker。<br>「Kube Proxy：」 负责在节点上实现Service的网络代理。</p>
<p>etcd：一款开源软件。提供可靠的分布式数据存储服务，用于持久化存储K8s集群的配置和状态</p>
<p>apiservice：用户程序（如kubectl）、K8s其它组件之间通信的接口。K8s其它组件之间不直接通信，而是通过API server通信的。这一点在上图的连接中可以体现，例如，只有API server连接了etcd，即其它组件更新K8s集群的状态时，只能通过API server读写etcd中的数据。</p>
<p>Scheduler：排程组件，为用户应用的每一可部署组件分配工作结点。</p>
<p>controller-manager：执行集群级别的功能，如复制组件、追踪工作结点状态、处理结点失败等。Controller Manager组件是由多个控制器组成的，其中很多控制器是按K8s的资源类型划分的，如Replication Manager（管理ReplicationController 资源），ReplicaSet Controller，PersistentVolume controller。</p>
<p>kube-proxy：在应用组件间负载均衡网络流量。</p>
<p>kubelet：管理工作结点上的容器。</p>
<p>Contriner runtime Docker， rkt等实际运行容器的组件</p>
<p>报错</p>
<p>报错</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/k8s/" rel="tag"># k8s</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/posts/e9f2e524.html" rel="next" title="java开发-Servlet及HttpSeverlet">
                <i class="fa fa-chevron-left"></i> java开发-Servlet及HttpSeverlet
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/posts/7052941e.html" rel="prev" title="DNS问题">
                DNS问题 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%7C%7C%20archive">
              
                  <span class="site-state-item-count">113</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">15</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">14</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81redhat-openEluer-22-Centos-%E7%B3%BB%E7%BB%9F-%E5%AE%89%E8%A3%85k8s"><span class="nav-number">1.</span> <span class="nav-text">一、redhat&#x2F;openEluer 22&#x2F;Centos 系统 安装k8s</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-1-%E6%9B%B4%E6%96%B0%E6%BA%90"><span class="nav-number">1.1.</span> <span class="nav-text">1.1 更新源</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2-%E5%AE%89%E8%A3%85-docker"><span class="nav-number">1.2.</span> <span class="nav-text">1.2 安装 docker</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-3-%E6%96%B0%E5%A2%9Ek8s%E6%BA%90%E5%8F%8A%E5%AE%89%E8%A3%85"><span class="nav-number">1.3.</span> <span class="nav-text">1.3 新增k8s源及安装</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81ubuntu-%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85-k8s"><span class="nav-number">2.</span> <span class="nav-text">二、ubuntu 系统安装 k8s</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E5%BF%85%E8%A6%81%E7%9A%84%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AE"><span class="nav-number">3.</span> <span class="nav-text">三、必要的系统设置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#3-1-%E5%85%B3%E9%97%AD-selinux-%E5%85%B3%E9%97%AD%E9%98%B2%E7%81%AB%E5%A2%99%E3%80%90%E6%9A%82%E6%97%B6%E3%80%91%EF%BC%88redhat%E7%B3%BB%E7%BB%9F%EF%BC%89"><span class="nav-number">3.1.</span> <span class="nav-text">3.1 关闭 selinux  关闭防火墙【暂时】（redhat系统）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-2-%E7%A6%81%E7%94%A8%E4%BA%A4%E6%8D%A2%E5%88%86%E5%8C%BA"><span class="nav-number">3.2.</span> <span class="nav-text">3.2 禁用交换分区</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-3-%E5%BC%80%E5%90%AF%E7%AB%AF%E5%8F%A3%E8%BD%AC%E5%8F%91"><span class="nav-number">3.3.</span> <span class="nav-text">3.3 开启端口转发</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-4-%E4%BF%AE%E6%94%B9%E5%86%85%E6%A0%B8%E5%8F%82%E6%95%B0"><span class="nav-number">3.4.</span> <span class="nav-text">3.4 修改内核参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-5-%E8%AE%BE%E7%BD%AE%E6%97%B6%E5%8C%BA%E6%9B%B4%E6%96%B0%E6%97%B6%E9%97%B4"><span class="nav-number">3.5.</span> <span class="nav-text">3.5 设置时区更新时间</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%85%8D%E7%BD%AEhost"><span class="nav-number">3.6.</span> <span class="nav-text">配置host</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81master-%E8%8A%82%E7%82%B9%E9%85%8D%E7%BD%AE"><span class="nav-number">4.</span> <span class="nav-text">三、master 节点配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#3-1-%E9%85%8D%E7%BD%AE%E9%A1%B9-%E8%A7%A3%E9%87%8A"><span class="nav-number">4.1.</span> <span class="nav-text">3.1 配置项 解释</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-2%E9%85%8D%E7%BD%AE%E7%A4%BA%E4%BE%8B%EF%BC%9A"><span class="nav-number">4.2.</span> <span class="nav-text">3.2配置示例：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-3-%E9%85%8D%E7%BD%AE-kubectl"><span class="nav-number">4.3.</span> <span class="nav-text">3.3 配置 kubectl</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-3-%E9%85%8D%E7%BD%AE%E7%BD%91%E7%BB%9C"><span class="nav-number">4.4.</span> <span class="nav-text">3.3 配置网络</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81node-%E8%8A%82%E7%82%B9%E9%85%8D%E7%BD%AE"><span class="nav-number">5.</span> <span class="nav-text">四、node 节点配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#4-1-%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%A4%84%E7%90%86"><span class="nav-number">5.1.</span> <span class="nav-text">4.1 配置文件处理</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-2-%E5%8A%A0%E5%85%A5%E8%8A%82%E7%82%B9"><span class="nav-number">5.2.</span> <span class="nav-text">4.2 加入节点</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%94%E3%80%81%E7%9B%B8%E5%85%B3%E5%91%BD%E4%BB%A4"><span class="nav-number">6.</span> <span class="nav-text">五、相关命令</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%85%AD-%E6%8A%A5%E9%94%99"><span class="nav-number">7.</span> <span class="nav-text">六 报错</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#k8%E7%BB%84%E4%BB%B6"><span class="nav-number">8.</span> <span class="nav-text">k8组件</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2025</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yszhao</span>

  
</div>






    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span id="busuanzi_container_site_pv">总访问量<span id="busuanzi_value_site_pv"></span>次</span>
    <span class="post-meta-divider">|</span>
    <span id="busuanzi_container_site_uv">总访客<span id="busuanzi_value_site_uv"></span>人</span>
    <span class="post-meta-divider">|</span>


        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
